<?php

use yii\db\Migration;


class m130524_201442_admin extends Migration
{

    public function up()
    {
        /**
         *  yii migrate --migrationPath=@yii/rbac/migrations
         */

        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = "CHARACTER SET utf8mb4 COLLATE utf8_unicode_ci ENGINE=InnoDB";
        }

        $this->createTable('{{%test}}', [
            'id' => $this->primaryKey(),
            'name' => $this->string(32)->notNull()->defaultValue(''),
            'created_at' => $this->integer()->notNull(),
            'updated_at' => $this->integer()->notNull(),
            'status' => $this->tinyInteger(1)->notNull()->defaultValue(1),
        ], $tableOptions);

        $this->createTable('{{%sys_login_log}}', [
            'app_id' => $this->string(32)->notNull()->defaultValue(''),
            'user_id' => $this->integer()->notNull(),
            'username' => $this->string(32)->notNull()->defaultValue(''),
            'type' => $this->tinyInteger(1)->notNull(),
            'ip' => $this->string(15)->notNull()->defaultValue(''),
            'created_at' => $this->integer()->notNull(),
        ], $tableOptions);

        $this->createTable('{{%sys_operation_log}}', [
            'user_id' => $this->integer()->notNull(),
            'user_info' => $this->string(32)->notNull()->defaultValue(''),
            'app_id' => $this->string(32)->notNull()->defaultValue(''),
            'version' => $this->string(32)->notNull()->defaultValue(''),
            'module' => $this->string(32)->notNull()->defaultValue(''),
            'controller' => $this->string(32)->notNull()->defaultValue(''),
            'action' => $this->string(32)->notNull()->defaultValue(''),
            'data' => $this->text()->notNull(),
            'ip' => $this->string(15)->notNull()->defaultValue(''),
            'created_at' => $this->integer()->notNull(),
        ], $tableOptions);

        //./yii migrate/to m140602_111327_create_menu_table.php  --migrationPath=@mdm/admin/migrations
    }

    public function down()
    {
        $this->dropTable('{{%test}}');
        $this->dropTable('{{%sys_login_log}}');
        $this->dropTable('{{%sys_operation_log}}');
    }
}
